package com.ropa.java.googleauthenticate;

import com.warrenstrange.googleauth.GoogleAuthenticator;
import com.warrenstrange.googleauth.ICredentialRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication
public class GoogleAuthenticateApplication {

    public static void main(String[] args) {
        SpringApplication.run(GoogleAuthenticateApplication.class, args);
    }



    @Bean
    public GoogleAuthenticator googleAuthenticator(){
        GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
        googleAuthenticator.setCredentialRepository(new ICredentialRepository() {

            private final Map<String, String> secretMap = new HashMap<>();

            @Override
            public String getSecretKey(String userName) {
                return secretMap.get(userName);
            }

            @Override
            public void saveUserCredentials(String userName, String secretKey, int validationCode, List<Integer> scratchCodes) {
                secretMap.put(userName, secretKey);
            }
        });
        return googleAuthenticator;
    }

}
